package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"math/rand"
	"strconv"
	"week/models"
)

type BroudController struct {
	beego.Controller
}

func (b *BroudController) CreateBroud() {
	anchor := b.GetString("anchor")
	anchorTitle := b.GetString("title")
	r := R()
	_, err := models.CreateBorud(models.BroudCast3{
		AnchorName:    anchor,
		AnchorTitle:   anchorTitle,
		AnchorSn:      r,
		PushMessage:   "rtmp://127.0.0.1/mylive",
		SowingMessage: "http://127.0.0.1/hLive/demo.html",
	})
	if err != nil {
		b.Data["json"] = map[string]interface{}{
			"code": 400,
			"msg":  "创建直播间失败",
		}
		b.ServeJSON()
		return
	}
	b.Data["json"] = map[string]interface{}{
		"code": 200,
		"msg":  "创建直播间成功",
	}
	b.ServeJSON()
}
func R() string {
	max := 99999999
	min := 10000000
	r := rand.Intn(max-min+1) + min
	return strconv.Itoa(r)
}
